package actions;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;
import javax.sql.rowset.CachedRowSet;

import model.ReviewerModel;
import model.StudentModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;

public class DisplayApplicationAction extends Action {


    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws DbException {
        int studentid = 0;
        
        // get particular student -> put his id in the request scope
        studentid = Integer.parseInt((String)request.getParameter("id"));
        request.getSession().setAttribute("studentid", studentid);
        
        // get all the reviewers associated with the student
        ArrayList<ArrayList> reviewers = StudentModel.getReviewers(studentid);
        request.getSession().setAttribute("reviewers", reviewers);
        
        // get all of his application data
        CachedRowSet application = StudentModel.fetchApplication(studentid);
        request.getSession().setAttribute("application", application);
                        
        return mapping.findForward("success");
    }
}
